/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package spriteeditor.sprite;

import java.awt.Graphics;
import java.util.ArrayList;

/**
 *
 * @author $L!M
 */
public class Animation
{
    ArrayList<Frame> frames = new ArrayList<Frame>();
    int delay = 100;
    int currFrameIndex = 0;

    
    public void update()
    {
        if(frames.isEmpty())
            return;
        currFrameIndex++;
        currFrameIndex %= frames.size();
    }
    public void paintAnimFrame(Graphics g, int x, int y)
    {
        if(frames.isEmpty())
            return;
        frames.get(currFrameIndex).paintFrame(g, x, y);
    }

    public void addFrame(Frame f)
    {
        frames.add(f);
    }

    public boolean moveFrame(int index, int dir)
    {
        if(index < 0 || index + dir < 0)
            return false;
        Frame f1 = frames.get(index);
        Frame f2 = frames.get(index + dir);
        if(f1 != null && f2 != null)
        {
            frames.set(index, f2);
            frames.set(index + dir, f1);
        }
        return true;
    }

    public boolean removeFrame(int index)
    {
        if(index < 0 || index >= frames.size())
            return false;
        frames.remove(index);
        currFrameIndex = 0;
        return true;
    }

    public void reset()
    {
        currFrameIndex ++;
    }
    public int getDelay() {
        return delay;
    }

    public void setDelay(int delay) {
        this.delay = delay;
    }

    public ArrayList<Frame> getFrames() {
        return frames;
    }

    public void setFrames(ArrayList<Frame> frames) {
        this.frames = frames;
    }

    public void setFrame(int index, Frame f) {
        frames.set(index, f);
    }

    public Frame getFrame(int index)
    {
        return frames.get(index);
    }

    public int getFramesCount()
    {
        return frames.size();
    }
}
